package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.album.service.VodService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Tag(name = "声音管理")
@RestController
@RequestMapping("api/album/trackInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class TrackInfoApiController {

	@Autowired
	private TrackInfoService trackInfoService;
	@Autowired
	private VodService vodService;



	@PostMapping("/uploadTrack")
	public Result<UploadTrackVo> uploadTrack(MultipartFile file){
		UploadTrackVo uploadTrackVo = trackInfoService.uploadTrack(file);
		return Result.build(uploadTrackVo,ResultCodeEnum.SUCCESS);
	}



	@GuiGuLogin
	@PostMapping("/saveTrackInfo")
	public Result saveTrackInfo(@RequestBody TrackInfoVo trackInfoVo){
		trackInfoService.saveTrackInfo(trackInfoVo);
		return  Result.build(null,ResultCodeEnum.SUCCESS);
	}
	@GuiGuLogin
	@PostMapping("/findUserTrackPage/{page}/{limit}")
	public Result<IPage<TrackListVo>> findUserTrackPage(@PathVariable(value = "page") Integer pageNum,
														   @PathVariable(value = "limit") Integer pageSize,
														   @RequestBody TrackInfoQuery trackInfoQuery){
		IPage<TrackListVo> page = trackInfoService.findUserTrackPage(pageNum,pageSize,trackInfoQuery);
		return Result.build(page, ResultCodeEnum.SUCCESS);
	}

	@GetMapping("/getTrackInfo/{id}")
	public Result<TrackInfo> getTrackInfo(@PathVariable Integer id){
		TrackInfo trackInfo = trackInfoService.getById(id);
		return Result.build(trackInfo,ResultCodeEnum.SUCCESS);
	}
	@PutMapping("/updateTrackInfo/{id}")
	public Result updateTrackInfo(@PathVariable(value = "id") Integer id,@RequestBody TrackInfoVo trackinfoVo){
		trackInfoService.updateTrackInfo(id,trackinfoVo);
		return Result.build(null,ResultCodeEnum.SUCCESS);
	}
	@DeleteMapping("/removeTrackInfo/{id}")
	public Result removeTrackInfo(@PathVariable Integer id){
		trackInfoService.removeTrackInfo(id);
		return Result.build(null,ResultCodeEnum.SUCCESS);
	}
	@Operation(summary = "获取专辑声音分页列表")
	@GuiGuLogin
	@GetMapping("/findAlbumTrackPage/{albumId}/{page}/{limit}")
	public Result<IPage<AlbumTrackListVo>> findAlbumTrackPage(@PathVariable(value = "albumId") Long albumId,
															  @PathVariable Long page,
															  @PathVariable Long limit){
		IPage<AlbumTrackListVo> trackListVoIPage = trackInfoService.findAlbumTrackPage(albumId,page,limit);
		return Result.build(trackListVoIPage,ResultCodeEnum.SUCCESS);

	}
	@Operation(summary = "获取声音统计信息")
	@GetMapping("/getTrackStatVo/{trackId}")
	public Result<TrackStatVo> getTrackStatVo(@PathVariable Long trackId){
		TrackStatVo trackStatVo = trackInfoService.getTrackStatVo(trackId);
		return Result.build(trackStatVo,ResultCodeEnum.SUCCESS);
	}

}

